<!DOCTYPE html>
<html lang="zh-CN">

<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>会员中心 - 光大好车</title>
	<meta content="光大好车" name="keywords" />
	<meta content="光大好车" name="description" />

	<link rel="stylesheet" href="css/news.css" />
	<link rel="stylesheet" href="css/style3.css" />
	<link rel="stylesheet" href="css/style4.css" />
	<link rel="stylesheet" type="text/css" href="css/style1.css">
	<link rel="stylesheet" type="text/css" href="css/style.css">
	<link rel="stylesheet" type="text/css" href="iconfont/iconfont.css">
	<script type="text/javascript" src="script/jquery.js"></script>
	<script type="text/javascript" src="script/jquery-3.3.1.min.js"></script>
	<script type="text/javascript" src="script/bootstrap.min.js"></script>
	<link rel="stylesheet" href="css/mui.min.css">
	<link rel="stylesheet" type="text/css" href="css/feedback-page.css" />


	<script src="js/mui.js"></script>
	<script src="js/mui.picker.min.js"></script>
	<script src="js/mui.picker.js"></script>
	<script src='js/feedback.js'></script>
	<script src="js/app.js"></script>
	<!--<script language="JavaScript">
			$(function() {
				$('.carnum').delay(2000).hide(0);
				$('.nextpage').click(function() {
					var nextpage = parseInt($("input[name=nextpage]").val());
					var page = parseInt($("input[name=page]").val());
					$.get("" + nextpage,
						function(data, textStatus) {
							if(data != '') {
								$("#listcar").append(data);
								$("input[name=page]").val(1);
							} else {
								$("#pagestatus").show().html("加载完毕，已没有更多车源");
								$(".nextpage").hide();
							}
						}
					);
					$("input[name=nextpage]").val(nextpage + 1);
				});
			})
		</script>-->
</head>

<body>
	<div class="black_overlay"></div>
	<!--内容-->
	<header class="mo-header">
		<div class="mo-header-left">
			<a href="#"> 首页 </a> <i class="mui-icon iconfont icon-youdayu"></i>
			<a href="#"> 会员中心 </a>
		</div>
	</header>
	<div class="user-logo-box" style="background-color: #FF6617">
		<div class="user-logo" id="myphoto"></div>
		<div class="user-name"></div>
	</div>
	<div class="user-tools">
		<ul class="mui-bar-tab">

			<!--<li><a id="feedback" href="feedback" class="mui-tab-item"><span class="help-word"><i class="mui-icon iconfont icon-youdayu"></i></span>意见反馈</a></li>-->
			<li>
				<a id="image" href="image" class="mui-tab-item"><span class="help-word"><i
							class="mui-icon iconfont icon-youdayu"></i></span>头像设置</a>
			</li>
			<li>
				<a id="collection" href="collection" class="mui-tab-item"><span class="help-word"><i
							class="mui-icon iconfont icon-youdayu"></i></span>我的收藏</a>
			</li>

			<li>
				<a id="message" href="message" class="mui-tab-item"><span class="help-word"><i
							class="mui-icon iconfont icon-youdayu"></i></span>我的消息</a>
			</li>

			<li>
				<a id="nickname" href="nickname" class="mui-tab-item"><span class="help-word"><i
							class="mui-icon iconfont icon-youdayu"></i></span>昵称设置</a>
			</li>
			<li>
				<a id="clearcache" href="clearcache" class="mui-tab-item"><span class="help-word"><i
							class="mui-icon iconfont icon-youdayu"></i></span>清理缓存</a>
			</li>
			<li>
				<a id="title" href="title" class="mui-tab-item"><span class="help-word"><i
							class="mui-icon iconfont icon-youdayu"></i></span>版本升级</a>
				<div id="demo1" class="mui-progressbar mui-progressbar-success" style="display: none;">
					<span></span>
				</div>
			</li>
		</ul>
		<label id="version" hidden="hidden">5.0</label>

	</div>
	<buttton class="user-menu" onclick="exit()">退出登录</button>
		<!--<a href="javascript:;" id="returntop"></a>-->
		<script type="text/javascript" src="script/jquery.lazyload.js"></script>
		<script>
			mui.back = function () {
				var btn = ["确定", "取消"];
				mui.confirm('确认关闭当前应用？', '提示', btn, function (e) {
					if (e.index == 0) {
						plus.runtime.quit();
					}
				});
			}
		</script>
		<script>
			(function ($, doc) {
					//					console.log("[main.html]inti...");
					$.init();
					console.log("[main.html]init完毕");

					var subpage_style = {
						top: '0px',
						bottom: '50px'
					};
					var subpages = ['member.html', 'activity.html'];
					//var aid="";
					$.plusReady(function () {
						//版本检查更新
						var version = doc.getElementById("version").innerHTML;
						var versionCode = "1.0.0";

						$.ajax({
							url: servicePath + "sechandcar/app/sys/selectVersion",
							async: false,
							type: "post",
							dataType: "json",
							success: function (data) {
								if (version != data[0].versioncode) {
									doc.getElementById("title").innerHTML =
										'<span class="help-word"><i class="mui-icon iconfont icon-youdayu"></i></span>有新版本更新<span class="mui-badge mui-badge-danger">New</span>';
									//alert("有新版本需要更新");
									versionCode = data[0].versioncode;
								}
							}
						});
						//					doc.getElementById("title").addEventListener('tap',function(){
						function toVersion() {

						}

						//					});

						var toVersion = function () {
							setTimeout(function () {
								var vname = doc.getElementById("version").innerText;
								console.log(vname);
								if (vname.indexOf('有新版本更新') != -1) {
									return;
								}

								var uppath = "";
								if (uppath != undefined && uppath != "") {
									plus.runtime.install(uppath, {
										force: true
									}, function () {
										//完成更新向服务器进行通知
										alert("更新完毕，将重启应用！");
										//FinishUpdate();  
										plus.runtime.restart();
									}, function (err) {
										//				                alert(JSON.stringify(err));
										//				                mui.toast("安装升级失败");
										downLoadFile(servicePath + 'sechandcar/apkfile/' +
											versionCode + '.apk');
										document.getElementById("demo1").style.cssText =
											"display: block;";
									});
								} else {

									downLoadFile(servicePath + 'sechandcar/apkfile/' + versionCode + '.apk');
									document.getElementById("demo1").style.cssText = "display: block;";
								}
							}, 0);
						};


						var toFeedback = function () {
							//$.fire(activityPage, 'show', null);
							setTimeout(function () {
								$.openWindow({
									url: 'feedback.html',
									id: 'feedback',
									preload: false,
									createNew: true,
									show: {
										aniShow: 'none'
									},
									styles: subpage_style,
									waiting: {
										autoShow: false
									},
									extras: {
										aaid: aid //传递菜单id
									}
								});
							}, 0);
						};

						//我的发布
						var toNickname = function () {
							//$.fire(activityPage, 'show', null);
							setTimeout(function () {
								location.href = "nickname.html"
							}, 0)

						};
						var toMyCollection = function () {
							//$.fire(activityPage, 'show', null);
							setTimeout(function () {
								$.openWindow({
									url: 'mycollection.html',
									id: 'collection',
									preload: false,
									show: {
										aniShow: 'none'
									},
									styles: subpage_style,
									waiting: {
										autoShow: false
									}
								});
							}, 0);
						};
						var toMessage = function () {
							setTimeout(function () {
								$.openWindow({
									url: 'mymsglist.html',
									id: 'message',
									preload: false,
									show: {
										aniShow: 'none'
									},
									styles: subpage_style,
									waiting: {
										autoShow: false
									}
								});
							}, 0);
						}
						mui('.mui-bar-tab').on('tap', 'a', function (e) {
							var targetTab = this.getAttribute('href');
							console.log("点击了" + JSON.stringify(targetTab));
							switch (targetTab) {
								case 'title':
									toVersion();
									break;
								case 'feedback':
									toFeedback();
									break;
								case 'nickname':
									toNickname();
									break;
								case 'collection':
									toMyCollection();
									break;
								case 'image':
									modifyphoto();
									break;
								case 'message':
									toMessage();
									break;
								case 'clearcache':
									alert('清理成功！');
									break;
							}
						});
					});
				}
				(mui, document));

			//下载
			function downLoadFile(urls) {

				var d = plus.downloader.createDownload(urls, {}, function (f, s) {

					//document.getElementById("version").innerText="新版已下载";
					ConfirmBox("下载完成，是否立即更新", function () {
						//存储安装包路径
						localStorage.setItem("upgradePath", f.filename);
						plus.runtime.install(f.filename, {
							force: true
						}, function () {
							//完成更新向服务器进行通知
							alert("更新完毕，将重启应用！");
							//FinishUpdate();
							plus.runtime.restart();
						}, function (err) {
							alert(JSON.stringify(err));
							mui.toast("安装升级失败");
						});
					}, function () {
						return;
					});
				}, function () {
					alert("下载失败", function () {});
				});

				d.addEventListener('statechanged', function (download, status) {

					//		console.log(JSON.stringify(download));
					if (download.state == 3 && status == 200) {
						var percent = Math.round((download.downloadedSize / download.totalSize) * 100);
						//document.getElementById("Progress_Button").innerHTML = (percent + "%");
						mui("#demo1").progressbar({
							progress: percent
						}).show();
					} else if (download.state == 4) {}
				}, false);
				d.start();
			}
			//确认消息
			function ConfirmBox(MSG, OKFN, CancelFN) {
				plus.nativeUI.confirm(MSG, function (e) {
					if (e.index == 0) {
						OKFN();
					} else {
						CancelFN();
					}
				}, "提示", ["确定", "取消"]);
			}
		</script>
		<script>
			var telephone = window.localStorage.getItem("telephone");
			$.ajax({
				url: servicePath + "sechandcar/app/users/shcUser/selectMyImgsrc",
				async: false,
				type: "post",
				dataType: "json",
				data: {
					"telephone": telephone
				},
				success: function (data) {
					//alert(data.image);
					//$("#myphoto").attr("src", servicePath+data.image);
					$('.user-logo').attr("style", "background:url(" + servicePath + "" + data.image +
						");background-size: 100% 100%")
					$(".user-name").html(data.nickname);
				}
			});
			var files = [];

			function modifyphoto() {
				showActionSheet();
			}

			// 添加文件  
			var index = 1;
			var newUrlAfterCompress;

			function appendFile(p) {
				if (files != []) {
					files.splice(0, files.length);
				}
				//				
				files.push({
					path: p,
					name: "photo_" + index
				});
				upload();

			}

			function upload() {
				var wt = plus.nativeUI.showWaiting();

				var task = plus.uploader.createUpload(servicePath + 'sechandcar/app/sys/modifyphoto', {
						method: "POST"
					},
					function (t, status) { //上传完成  
						if (status == 200) {
							if (t.responseText != '') {
								$('.user-logo').attr("style", "background:url(" + servicePath + "" + t.responseText +
									");background-size: 100% 100%")
								mui.toast('头像设置成功');
								wt.close();
							} else {
								alert('头像设置失败');
								wt.close();
							}

						} else {
							console.log("头像设置失败：" + status);
							wt.close();
						}
					}
				);
				alert('成功选择一张照片');
				if (files.length > 0) {
					for (var i = 0; i < files.length; i++) {
						var f = files[files.length - 1];
						//	alert(f.path);
						task.addFile(f.path, {
							key: f.name
						});
					}

				}
				task.addData('telephone', telephone);

				task.start();

			}
			// 产生一个随机数  
			function getUid() {
				return Math.floor(Math.random() * 100000000 + 10000000).toString();
			}

			function galleryImgs() { // 从相册中选择图片  
				plus.gallery.pick(function (e) {
					//					console.log("选择了" + e.files.length + "个图片");
					//					for(var i = 0; i < e.files.length; i++) {
					//						if(i < 9) {
					//							var _str = "<span class='pic_look col-md-1 col-xs-4' style='background-image: url(" + e.files[i] + ")'><em id='delete_pic'>-</em></span>";
					//							$('#chose_pic_btn').before(_str);
					var dstname = "_downloads/" + getUid() + ".jpg"; //设置压缩后图片的路径  
					newUrlAfterCompress = compressImage(e.files[0], dstname);
					appendFile(dstname);
					//						}
					//					}
				}, function (e) {
					console.log("取消选择图片");
				}, {
					filter: "image",
					multiple: true
				});
			}

			//压缩图片，这个比较变态的方法，无法return  
			function compressImage(src, dstname) {
				plus.zip.compressImage({
						src: src,
						dst: dstname,
						overwrite: true,
						quality: 20
					},
					function (event) {
						return event.target;
					},
					function (error) {
						console.log(error);
						return src;
					});

			}

			function showActionSheet() {
				var bts = [{
					title: "拍照"
				}, {
					title: "从相册选择"
				}];
				plus.nativeUI.actionSheet({
						cancel: "取消",
						buttons: bts
					},
					function (e) {
						if (e.index == 1) {
							getImage();
						} else if (e.index == 2) {
							galleryImgs();
						}
					}
				);
			}
			//拍照  
			function getImage() {
				var cmr = plus.camera.getCamera();
				cmr.captureImage(function (p) {
					plus.io.resolveLocalFileSystemURL(p, function (entry) {
						var localurl = entry.toLocalURL(); //  
						//						var _str = "<span class='pic_look col-md-1 col-xs-4' style='background-image: url(" + localurl + ")'><em id='delete_pic'>-</em></span>";
						//						$('#chose_pic_btn').before(_str);
						var dstname = "_downloads/" + getUid() + ".jpg"; //设置压缩后图片的路径  
						newUrlAfterCompress = compressImage(localurl, dstname);
						appendFile(dstname);
					});
				});
			}

			function exit() {
				window.localStorage.clear();
				//alert(window.localStorage.getItem("telephone"));
				window.top.location.replace("login.html");
				//window.location.href = "login.html";
			}
		</script>
</body>

</html>